﻿using Microsoft.AspNetCore.Mvc;
using star_questionnair.Services;

namespace star_questionnair.Controllers;

[Route("timeAnalysis")]
[ApiController]
public class TimeController : ControllerBase
{
    private readonly ITimeService _timeService;

    // 构造函数注入 TimeService
    public TimeController(ITimeService timeService)
    {
        _timeService = timeService;
    }

    // 返回问卷的平均完成时间
    [HttpGet("averageTime/{questionnaireId}")]
    public async Task<IActionResult> AverageFinishedTime(int questionnaireId)
    {
        var result = await _timeService.AverageFinishedTimeAsync(questionnaireId);
        return Ok(result); // 返回计算的平均时间
    }

    // 返回时间段填写人数
    [HttpGet("timePeriod/{questionnaireId}")]
    public async Task<IActionResult> ResponsesByTimePeriod(int questionnaireId)
    {
        var result = await _timeService.GetResponsesByTimePeriodAsync(questionnaireId);
        return Ok(result); // 返回按时间段划分的填写人数
    }

    // 返回一周每天的填写量
    [HttpGet("dayPeriod/{questionnaireId}")]
    public async Task<IActionResult> ResponsesByDay(int questionnaireId)
    {
        var result = await _timeService.GetResponsesByDayOfWeekAsync(questionnaireId);
        return Ok(result); // 返回按星期几划分的填写量
    }
}